package sy8_3;

import java.util.*;

public class demo {
    public static void main(String[] args) {
        HashMap<String,String> hashMap=new HashMap();
        hashMap.put("Tom","CoreJava");
        hashMap.put("John","Oracle");
        hashMap.put("Susan","Oracle");
        hashMap.put("Jerry","JDBC");
        hashMap.put("Jim","Unix");
        hashMap.put("Kevin","JSP");
        hashMap.put("Lucy","JSP");
        System.out.println(hashMap);
        Set<String> keySet = hashMap.keySet();
        Collection<String> values = hashMap.values();
        outputHashMap(hashMap);
        System.out.println("===============新增================");
        hashMap.put("Allen","JDBC");
        outputHashMap(hashMap);
        System.out.println("==========修改============");
        hashMap.put("Lucy","CoreJava");
        outputHashMap(hashMap);
        System.out.println("==============输出JSP老师=========================");
        outputJSPTeacher(hashMap);

    }
    private static void outputJSPTeacher(HashMap<String, String> hashMap) {
        Set<Map.Entry<String, String>> entries = hashMap.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        while(iterator.hasNext()){
            Map.Entry<String, String> entry = iterator.next();
            String lessonName = entry.getValue();
            if("JSP".equals(lessonName)) {
                String teacherName = entry.getKey();
                System.out.println("techerName:"+teacherName+",lessonName:"+lessonName);
            }
        }
    }
    private static void outputHashMap(HashMap<String,String> hashMap) {
        Set<Map.Entry<String, String>> entries = hashMap.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        while (iterator.hasNext()){
            Map.Entry<String, String> entry = iterator.next();
            String techerName = entry.getKey();
            String lessonName = entry.getValue();
            System.out.println("techerName:"+techerName+",lessonName:"+lessonName);
        }
    }

}
